package com.example.wendao.view.ui.fragment;

import android.os.Bundle;

import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.wendao.R;
import com.example.wendao.common.PageUtils;
import com.example.wendao.databinding.FragmentViewPagerTestBinding;
import com.example.wendao.model.entity.User;
import com.example.wendao.view.adapter.UserListAdapter;
import com.example.wendao.viewmodel.UserViewModel;

public class ViewPagerTestFragment extends Fragment {


    UserViewModel userViewModel = null;
    UserListAdapter adapter = new UserListAdapter();
    FragmentViewPagerTestBinding binding;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(inflater, R.layout.fragment_view_pager_test, container, false);

        userViewModel = new ViewModelProvider(this).get(UserViewModel.class);

        PageUtils.initRecyclerView(binding.rvTestViewpager, adapter, new LinearLayoutManager(this.getContext()));

        userViewModel.getAllUser().observe(this.getViewLifecycleOwner(), adapter::submitList);

        return binding.getRoot();
    }
}